package com.kun.kunkunmall.order.web;

import com.kun.kunkunmall.order.service.AliPayService;
import com.kun.kunkunmall.order.service.OrderService;
import com.kun.kunkunmall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PayWebController {

    @Autowired
    AliPayService aliPayService;

    @Autowired
    OrderService orderService;

    @GetMapping(value = "/payOrder",produces = "text/html")
    @ResponseBody
    public String payOrder(@RequestParam(value = "orderSn",required = true) String orderSn){

        PayVo payVo =orderService.getOrderPay(orderSn); // 获取订单支付所需要的信息
        try {
            // 支付成功
            String s = aliPayService.webPagePay(payVo.getOut_trade_no(), payVo.getTotal_amount(), payVo.getSubject());
            System.out.println(s);
            return s;
        }catch (Exception e){
            // 支付失败
        }
        return "fail";
    }
}
